package edu.sjb.map;

import javax.swing.ImageIcon;

import edu.sjb.map.prizes.Prize;
import edu.sjb.map.prizes.ReleasedPrize;

public abstract class GenericMapElementFactory {
	public static final ImageIcon TRANS  = new ImageIcon("./images/transparent.png");
	public static final ImageIcon COMMON = new ImageIcon("./images/objects/brick_common.gif");
	public static final ImageIcon SOLID  = new ImageIcon("./images/objects/brick_solid.png");
	public static final ImageIcon QM     = new ImageIcon("./images/objects/brick_qm.gif");
	public static final ImageIcon BLOCK  = new ImageIcon("./images/level-border.png");
	public static final ImageIcon GOAL   = new ImageIcon("./images/goal-transparent.png");
	
	public static GenericMapElement emptySpace() {
		return new GenericMapElement(TRANS, new EmptySpace());
	}

	public static GenericMapElement bottomlessPit() {
		return new GenericMapElement(TRANS, new BottomlessPit());
	}

	public static GenericMapElement goalEntity() {
		return new GenericMapElement(GOAL, new GoalPoint());
	}
	

	public static GenericMapElement brick(int params) {
		boolean s  = (params & MapLoader.MASK_IS_SOLID) != 0; //10h
		boolean qm = (params & MapLoader.MASK_IS_QM)    != 0; //20h
		boolean o  = (params & MapLoader.MASK_OPAQUE)   != 0; //40h 
		MapBrick mb = null;
		ImageIcon img = null;
		int sub_mask = (qm? MapLoader.MASK_IS_QM: 0) | (s? MapLoader.MASK_IS_SOLID: 0) |(o? MapLoader.MASK_OPAQUE: 0);
		switch (params ^ sub_mask) {
			case MapLoader.MASK_00COINS:
				mb = MapBrickFactory.commonBrick(qm);
				switch (sub_mask / 16) {
					case 0: img = TRANS;  break;
					case 1: img = BLOCK;  break;
					case 2: img = TRANS;  break;
					case 3: img = TRANS;  break;
					case 4: img = COMMON; break;
					case 5: img = SOLID;  break;
					case 6: img = QM;     break;
					case 7: img = QM;     break;
				}
				break;
			case MapLoader.MASK_01COINS:
				mb = MapBrickFactory.oneCoinBrick(qm, o);
				if (o)
					if (qm)
						img = QM; // = f1
					else
						img = COMMON; // = d1
				else
					img = TRANS; // = 91
				break;
			case MapLoader.MASK_10COINS:
				mb = MapBrickFactory.tenCoinBrick(qm);
				img = qm? QM: COMMON; // = f2 /  = b2
				break;
			case MapLoader.MASK_MUSHROOM:
				mb = MapBrickFactory.mushroomBrick();
				img = QM; //f3
				break;
			case MapLoader.MASK_FLOWER:
				mb = MapBrickFactory.flowerBrick();
				img = QM; //f4
				break;
			case MapLoader.MASK_STAR:
				mb = MapBrickFactory.starBrick();
				img = QM; //f5
				break;
			case MapLoader.MASK_NUCBOMB:
				mb = MapBrickFactory.bombBrick();
				img = QM; //f6
				break;
			case MapLoader.MASK_MUSH1UP:
				mb = MapBrickFactory.mushroom1UPBrick(o);
				img = o? QM: TRANS; //f7 / b7
				break;
		}
		return new GenericMapElement(img, mb);
	}
	
	public static GenericMapElement releasedPrize(Prize p) {
		return new GenericMapElement(p.getImage(), new ReleasedPrize(p));
	}
}
